package com.mooc.yohoshop.ui.seckillvalues;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mooc.yohoshop.App;
import com.mooc.yohoshop.R;
import com.mooc.yohoshop.dao.DaoDBUtils;
import com.mooc.yohoshop.entity.BaseEntity;
import com.mooc.yohoshop.entity.OffLineCarEntity;
import com.mooc.yohoshop.entity.SecKillValuesEntity;
import com.mooc.yohoshop.imgload.ImageLoad;
import com.mooc.yohoshop.ui.base.BaseActivity;
import com.mooc.yohoshop.ui.car.CarActivity;

import java.util.HashMap;

public class SecKillValuesActivity extends BaseActivity<SecKillValuesRepo> implements View.OnClickListener {

    private long id;
    private ImageView skill_value_img1,skill_value_img2,skill_value_img3,value_head_img;
    private TextView value_head_title,value_head_dec,mSkuSelectedTv;

    @Override
    protected int layout() {
        return R.layout.activity_seckill_values;
    }

    @Override
    protected void init() {
        f(R.id.back).setOnClickListener(this::onClick);
        f(R.id.seckill_values_share_tv).setOnClickListener(this::onClick);
        f(R.id.seckill_values_car_tv).setOnClickListener(this::onClick);
        f(R.id.seckill_values_add_car).setOnClickListener(this::onClick);
        skill_value_img1 = f(R.id.skill_value_img1);
        skill_value_img2 = f(R.id.skill_value_img2);
        skill_value_img3 = f(R.id.skill_value_img3);
        value_head_img = f(R.id.value_head_img);
        value_head_title = f(R.id.value_head_title);
        value_head_dec = f(R.id.value_head_dec);
        id = getIntent().getLongExtra("id",0);
    }

    @Override
    protected void initData() {
        HashMap<String,Object>map=new HashMap<>();
        map.put("goodsId",id);
        request(repo.requestValues(map));
    }
    SecKillValuesEntity entity;
    @Override
    protected void result(BaseEntity baseEntity) {
        entity = (SecKillValuesEntity) baseEntity;
        ImageLoad.loadMatchUrl(entity.data.goods_detail_one,skill_value_img1);
        ImageLoad.loadMatchUrl(entity.data.goods_detail_two,skill_value_img2);
        ImageLoad.loadMatchUrl(entity.data.goods_detail_one,skill_value_img3);
        ImageLoad.loadMatchUrl(entity.data.goods_default_icon,value_head_img);
        value_head_title.setText(entity.data.goods_default_sku);
        value_head_dec.setText(entity.data.goods_desc);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (R.id.back == id){
            finish();
        }else  if (R.id.seckill_values_share_tv == id){

        }else  if (R.id.seckill_values_car_tv == id){
            startActivity(new Intent(this, CarActivity.class));
        }else if (R.id.seckill_values_add_car == id){
            if (App.getInstance().isLogin()){

            }else {
                if (entity == null)
                    return;
                OffLineCarEntity offEntity = new OffLineCarEntity();
                offEntity.goods_id = entity.data.id;
                offEntity.shop_name = entity.data.goods_default_sku;
                offEntity.shop_num = ""+1;
                offEntity.shop_color = "红";
                offEntity.shop_price = ""+entity.data.goods_default_price;
                offEntity.shop_size = "XL";
                offEntity.car_path = entity.data.goods_default_icon;
                offEntity.shop_select = "1";
                DaoDBUtils.getInstance().getDaoSession().getOffLineCarEntityDao()
                        .insert(offEntity);
            }
        }
    }
}
